<script>
	import {
		getAppVersion,
	} from '@/common/api/index';
	export default {
		globalData: {
			update:null,   
			updateOpen:false,
		},            
		onLaunch: function() {
			// 更新
			// #ifdef APP-PLUS
			this.checkVersion()  
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			//当前应用版本号
			async checkVersion(){
				const pages = getCurrentPages(); //当前页
				let platform = uni.getSystemInfoSync().platform.toLowerCase()
					getAppVersion({
						type: platform == 'android' ? 2 : 1,
					}).then(res => {
					}).catch((res) => {
						res.data = JSON.parse(res.data )
						if(res.data && res.data.version){
							plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
								let newVersion = res.data.version.replace('.', '');	 //最新新版本
								let currentVersion = wgtinfo.version.replace('.', '');//当前APP版本
								// 普通更新
									if(Number(newVersion) > Number(currentVersion)){
										//更新类型
										getApp().globalData.update = res.data
										getApp().globalData.updateOpen = true
									}
									
									// else{
									// 	let upgrade_info = uni.getStorageSync("UPGRADE_INFO") || {}
									// 	uni.setStorageSync("UPGRADE_INFO",{})
									// 	if(upgrade_info.tempFilePath){
									// 		uni.removeSavedFile({
									// 			filePath: upgrade_info.tempFilePath,
									// 			complete: function(res) { 
									// 				console.log("文件删除成功",res)
									// 			}  
									// 		}); 				    
									// 	}
									// }
									
									if(getApp().globalData.updateOpen){
										uni.navigateTo({
											url: '/pages/upgrade/index' 
										});
									}  
							})
						}
					})
			}, 
		}
	}
</script>
<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	page{
		background: #F5F5F5;
	}
</style>
